/**
 * @author luguoxiang
 * @date 2021-09-07
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import request from '@/soar/utils/request';

const baseUri = '/system/sys-config';

/**
 * 获取配置
 * @param code
 */
function get(code: string): Promise<any> {
  return request.get(`${baseUri}/${code}`).then((res) => JSON.parse(res.data || "{}"));
}

/**
 * 获取多个配置
 */
function map(codes: string|string[]): Promise<any> {
  return request.get(`${baseUri}/map`, { params: { codes } }).then((res) => {
    for (const k in res.data) {
      res.data[k] = JSON.parse(res.data[k] || "{}");
    }
    return res;
  });
}

export default {
  get,
  map,
};
